# Contributor: Kevin Daudt <kdaudt@alpinelinux.org>
# Maintainer: Kevin Daudt <kdaudt@alpinelinux.org>
pkgname=zabbix-agent2-alpine
pkgver=5.0.2
pkgrel=0
_plugins_version=0.2
pkgdesc="Zabbix Agent2 with additional plugins"
url="https://gitlab.alpinelinux.org/alpine/infra/infra-packages/-/tree/master/infra/zabbix-agent2-alpine"
arch="all !mips !mips64" # missing go
license="GPL-2.0-or-later"
makedepends="go autoconf automake pcre-dev zlib-dev openssl-dev openssl-libs-static"
options="!check" # no test suite
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/zabbix/zabbix/archive/$pkgver.tar.gz
	https://gitlab.alpinelinux.org/alpine/infra/zabbix-agent2-plugins/-/archive/v$_plugins_version/zabbix-agent2-plugins-v$_plugins_version.tar.gz
	zabbix-agent2.initd
	zabbix_agent2.conf
	enable-plugins.patch
	"
install="$pkgname.pre-install"
builddir="$srcdir/zabbix-$pkgver"

prepare() {
	default_prepare
	./bootstrap.sh

	cp -r "$srcdir"/zabbix-agent2-plugins-v$_plugins_version/plugins/* \
		"$builddir"/src/go/plugins/
}

build() {
	./configure \
		--sysconfdir=/etc/zabbix \
		--mandir=/usr/share/man \
		--with-openssl \
		--enable-agent2 \
		--enable-static
	make
}

package() {
	install -Dm0755 src/go/bin/zabbix_agent2 $pkgdir/usr/sbin/zabbix_agent2
	install -Dm0755 $srcdir/zabbix-agent2.initd $pkgdir/etc/init.d/zabbix-agent2
	install -dm0755 $pkgdir/etc/zabbix/agent2.conf.d/

	install -Dm0644 $srcdir/zabbix_agent2.conf $pkgdir/etc/zabbix/zabbix_agent2.conf
}

sha512sums="4ec2fb5b8a8a74873faf126025f5810d0d453cd5f83527d012bfe1d52716ae37990562834c9817d70282c66db515efaa1a3aff025377c63c6e6e93cc35d5f810  zabbix-agent2-alpine-5.0.2.tar.gz
1270b0d4166aba0e199ea66ed870eafc1fb65ed2c49317e35567504ad651ea294849656ea0b98172b896a91eeb5c87c692217a986e6bc6ed896498e7c7776197  zabbix-agent2-plugins-v0.2.tar.gz
177fafc9534a1107f91b428ddf2655e0ef617c417189afa40e3bb34b1e8492dafd53db5845fd97096b90b846da2cc27775d1bea942b0f6f8275de49778b8c154  zabbix-agent2.initd
a5668a01ef840f63516b86976f27906f1e4689fb7c1fd0864ce82028d2405fc6a5ba3b9d1bfa2828343935cbeb5fd9c6c7aba4bf1a00e3e301b12199ea61bd13  zabbix_agent2.conf
fb5b237edd229c6300867084810c9bb051e9c7ee09fc4499837d8be9f99678549de757cf2c5dbecf513322e4705e7ea2be8e4f4965fded3d09a10a69ec17b37e  enable-plugins.patch"
